package com.ms.domain.entity;

import com.baomidou.mybatisplus.annotation.*;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.ms.constant.GenderTypeConstant;
import com.ms.constant.RoleConstants;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serial;
import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.Date;

/**
 * 用户实体（包含普通用户和管理员）
 */
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@TableName(value = "user", autoResultMap = true)
public class User implements Serializable {
    @Serial
    private static final long serialVersionUID = 1L;

    @TableId(type = IdType.AUTO)
    private Integer id;

    @TableField(condition = SqlCondition.LIKE)
    private String username;

    @TableField(condition = SqlCondition.LIKE)
    private String nickname;

    private String password;
    private String email;

    private String gender = GenderTypeConstant.UNKNOWN;
    private String bio;

    @JsonFormat(pattern = "yyyy-MM-dd")
    private Date birthday;

    @TableField("avatar_url")
    private String avatarUrl;

    @TableField("background_url")
    private String backgroundUrl = "https://sky-take-ou7.oss-cn-beijing.aliyuncs.com/default_bg.jpg";

    // 角色权限（SUPER_ADMIN, CONTENT_ADMIN, USER）
    @TableField("role")
    private String role = RoleConstants.DEFAULT_ROLE;

    @TableField(value = "create_time", fill = FieldFill.INSERT)
    private LocalDateTime createTime;

    @TableField(value = "update_time", fill = FieldFill.INSERT_UPDATE)
    private LocalDateTime updateTime;

    // 便捷方法
    public boolean isAdmin() {
        return RoleConstants.SUPER_ADMIN.equals(role) || RoleConstants.CONTENT_ADMIN.equals(role);
    }
}